import axiosInstance from './axiosInstance';

interface GetProductsParams {
  page?: number;
  limit?: number;
  search?: string;
  category?: string;
  minPrice?: number;
  maxPrice?: number;
  sortBy?: string;
  featured?: boolean;
}

export const productService = {
  // 获取商品列表
  getProducts: async (params?: GetProductsParams) => {
    return axiosInstance.get('/products', { params });
  },

  // 获取单个商品详情
  getProduct: async (id: number) => {
    return axiosInstance.get(`/products/${id}`);
  },

  // 获取分类列表
  getCategories: async () => {
    return axiosInstance.get('/categories');
  },

  // 获取特色商品
  getFeaturedProducts: async (limit: number = 8) => {
    return axiosInstance.get('/products', {
      params: {
        featured: true,
        limit,
        sortBy: 'createdAt',
        sortOrder: 'DESC'
      }
    });
  }
};